from django.http import HttpResponse
from django.utils.deprecation import MiddlewareMixin
import traceback
from django.core import mail

class MyMW(MiddlewareMixin):
    def process_request(self,request):
        print('MyMw process_request do')

    def process_view(self,request,callback,callback_args,callback_kwargs):
        print('MyMw process_view do')


    def process_response(self,request,response):
        print('MyMw process_response do')
        return response


class ExceptionMW(MiddlewareMixin):
    def process_exception(self,request,exception):
        print(exception)
        print(traceback.format_exc())
        mail.send_mail(subject='mysite7报错',
                       message=traceback.format_exc(),
                       from_email='2579726986@qq.com',
                       recipient_list=['2579726986@qq.com']
        )
        return HttpResponse('__当前网页忙')